package com.kkkkkba.search.controller;

import com.google.gson.Gson;
import com.kkkkkba.search.common.BaseResponse;
import com.kkkkkba.search.common.ResultUtils;
import com.kkkkkba.search.manager.SearchFacade;
import com.kkkkkba.search.model.dto.search.SearchRequest;
import com.kkkkkba.search.model.vo.SearchPageVo;
import com.kkkkkba.search.model.vo.SearchVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 查询接口
 */
@RestController
@RequestMapping("/search")
@Slf4j
@Api(tags = "搜索接口")
public class SearchController {

    @Resource
    private SearchFacade searchFacade;

    private final static Gson GSON = new Gson();

    /**
     * 聚合搜索
     *
     * @param searchRequest
     * @param request
     * @return
     */
    @PostMapping("/all")
    public BaseResponse<SearchVO> doSearchAll(@RequestBody SearchRequest searchRequest, HttpServletRequest request) {
        return ResultUtils.success(searchFacade.doSearchAll(searchRequest,request));
    }

    /**
     * 聚合搜索分页
     *
     * @param searchRequest
     * @param request
     * @return
     */
    @PostMapping("/page/all")
    public BaseResponse<SearchPageVo> doSearchByPage(@RequestBody SearchRequest searchRequest, HttpServletRequest request) {
        return ResultUtils.success(searchFacade.doSearchByPage(searchRequest,request));
    }
}
